<template>
  <div class="admin">
    <!-- 公用组件 -->
    <el-container>
      <el-aside>
        <el-menu
          default-active="2"
          background-color="#545c64"
          text-color="#fff"
          active-text-color="#ffd04b"
          router
        >
          <el-menu-item
            :index="item.path"
            v-for="item in menus"
            :key="item.path"
          >
            <span slot="title">{{ item.name }}</span>
          </el-menu-item>
        </el-menu>
      </el-aside>

      <el-container>
        <el-header>
          <span>首页</span>
          <el-button @click="onLogoutClicked">退出登录</el-button>
        </el-header>

        <el-main>
          <!-- 路由占位 -->
          <router-view />
        </el-main>
      </el-container>
    </el-container>
  </div>
</template>

<script>
export default {
  data() {
    return {
      menus: JSON.parse(window.sessionStorage.getItem("menus"))
    };
  },
  methods: {
    onLogoutClicked() {
      window.sessionStorage.clear();
      this.$router.push("/login");
    }
  }
};
</script>

<style lang="less" scope>
.admin {
  height: 100%;

  .el-container,
  .el-aside,
  .el-main,
  .el-menu {
    height: 100%;
  }

  .el-header {
    height: 56px;
    background-color: #a9cffb;
    display: flex;
    justify-content: space-between;
    align-items: center;
    color: #fff;
  }
}
</style>
